<template>
  <el-menu
    :default-active="activeIndex2"
    class="el-menu-demo"
    mode="horizontal"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
  >
    <el-menu-item index="1">
      <router-link to="/list" style="text-decoration: none">
        全部商品</router-link
      >
    </el-menu-item>
    <el-submenu index="2">
      <template slot="title">我</template>
      <el-menu-item index="2-1">
        <router-link
          to="/personinfo"
          style="text-decoration: none; color: #ffffff"
          >我的资料</router-link
        >
      </el-menu-item>
      <el-menu-item index="2-2">
        <router-link
          to="/orderlist"
          style="text-decoration: none; color: #ffffff"
          >我的订单</router-link
        >
      </el-menu-item>
      <el-menu-item index="2-3" @click="onExit">退出登录</el-menu-item>
    </el-submenu>

  </el-menu>
</template>

<script>
import {logout} from '@/api/user';

export default {
  name: "Top",
  data() {
    return {
      activeIndex: "1",
      activeIndex2: "1",
    };
  },
  methods: {
    onExit() {
      // 退出登录
      logout().then(res => {
        sessionStorage.removeItem("token");
        this.$message.success(res.msg);
        this.$router.push('/')
      })
    },
  },
};
</script>

<style>
</style>